package cn.zhentao.speechai.controller;

import cn.zhentao.speechai.service.VoiceRecognizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/voice")
public class VoiceController {
    
    @Autowired
    private VoiceRecognizeService voiceRecognizeService;
    
    @GetMapping("/test")
    public Map<String, Object> test() {
        Map<String, Object> response = new HashMap<>();
        response.put("status", "success");
        response.put("message", "Speech-ai service is running");
        response.put("timestamp", System.currentTimeMillis());
        return response;
    }
    
    @PostMapping("/recognize")
    public Map<String, Object> voiceRecognize(
            @RequestParam("audio") MultipartFile audioFile,
            @RequestParam(value = "format", defaultValue = "aac") String format,
            @RequestParam(value = "sampleRate", defaultValue = "16000") int sampleRate) {
        
        return voiceRecognizeService.recognizeAudio(audioFile, format, sampleRate);
    }
}